/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.coreGenerator.base.serializer.changeser.entity.serializer;

import com.inspur.edp.caf.generator.baseInfo.ParameterInfo;
import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
import org.eclipse.jdt.core.dom.*;

import java.util.ArrayList;

public class NodeDataChangeSerCtorGenerator extends ClassMethodGenerator {
    private NodeDataChangeSerGenContext ndcSerGenContext;
    private String className;
    private boolean isRoot;

    public NodeDataChangeSerCtorGenerator(String className, boolean isRoot, NodeDataChangeSerGenContext ndcSerGenContext) {
        super();
        this.className = className;
        this.isRoot = isRoot;
        this.ndcSerGenContext = ndcSerGenContext;
    }

    @Override
    protected boolean buildIsConstructor() {
        return true;
    }

    @Override
    protected String getMethodName() {
        return className;
    }

    @Override
    protected TypeInfo getReturnType() {
        return null;
    }

    @Override
    protected Block buildMethodBody() {
        SuperConstructorInvocation superConstructorInvocation = ast.newSuperConstructorInvocation();
        StringLiteral stringLiteral = ast.newStringLiteral();
        stringLiteral.setLiteralValue(ndcSerGenContext.getNodeCode());
        superConstructorInvocation.arguments().add(stringLiteral);
        superConstructorInvocation.arguments().add(ast.newBooleanLiteral(isRoot));
        MethodInvocation methodInvocation = ast.newMethodInvocation();
        methodInvocation.setName(ast.newSimpleName(NodeDataSerGetTypesGenerator.getTypesMethodName()));
        superConstructorInvocation.arguments().add(methodInvocation);
        Block block = ast.newBlock();
        block.statements().add(superConstructorInvocation);
        return block;
    }

    @Override
    protected ArrayList<Modifier.ModifierKeyword> getAccessModifiers() {
        ArrayList<Modifier.ModifierKeyword> list = new ArrayList<>();
        list.add(Modifier.ModifierKeyword.PUBLIC_KEYWORD);

        return list;
    }

    @Override
    protected ArrayList<ParameterInfo> getParameterCollection() {
        ArrayList<ParameterInfo> list = new ArrayList<ParameterInfo>();
        return list;
    }
}
